<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>查找</title>
	<style type="text/css">
		*{
			margin:0px;
			padding:0px;
		}
		#container{
			width: 100%;
			height:1000px;
			margin: 0px auto;
			background: #111111;
		}
		#top{
			width:100%;
			height:50px;
			background-color:#06D995;
			color: #fff;
			line-height: 50px;
			font-family: 宋体;
		}
		#main{
			width:100%;
			height: auto;
		}
		#search{
			width: 96%;
			height: 55PX;
			margin: 20px 2%;
			/*background-color: blue;*/
		}
		.selector{
			width: 150px;
			height: 45px;
			margin-top: 5px;
			border-radius: 5px;
			/*color: red;*/

		}
		.selector option{
			/*color: red;*/
			/*text-align: center;*/
		}
		.search_button{
			width: 60px;
			height: 35px;
			margin-top: 10px;
			border-radius: 3px;
			border:none;
		}
		.search_text{
			width: 180px;
			height: 41px;
			margin-top: 7px;
			padding: 0px 10px;
			font-size: 16px;
			font-family: 黑体;
			border-radius: 5px;
		}
		table{
			margin: 0px auto;
		}
		table th,td{
			padding: 5px 10px;
			text-align: center;
		}
		.searchResult{
			display: none;
		}
		.searchResultBlock{
			display: block;
		}
		.foot{
			color: #fff;
		}
	</style>
	<script src="/Storey/Public/js/jquery.min.js"></script>
</head>
<body>
	<div id="container">
		<div id="top">
			<h1>消防监测后台管理系统</h1>
		</div>
		<div id="main">
			<div id="search">
					<!-- <form method="post" action="<?php echo U('Index/classifySearch');?>"> -->
					<form>
						<select class="selector" id="regionNum" name="regionNum">
							<!-- <option value="">-按地区-</option> -->
							<option value="">所有地区</option>
							<?php if(is_array($info1)): foreach($info1 as $key=>$v): ?><option value="<?php echo ($v["regionnum"]); ?>"><?php echo ($v["regionnum"]); ?></option><?php endforeach; endif; ?>
						</select>&nbsp;&nbsp;
						<select class="selector" id="deviceType" name="deviceType">
							<!-- <option value="">-按设备类型-</option> -->
							<option value="">所有设备</option>
							<?php if(is_array($info)): foreach($info as $key=>$v): ?><option value="<?php echo ($v["devicetype"]); ?>"><?php echo ($v["devicetype"]); ?></option><?php endforeach; endif; ?>
						</select>&nbsp;&nbsp;
						<b style="color: #fff">或</b>&nbsp;&nbsp;
						<input class="search_text" id="chipId" type="text" name="chipId" placeholder="-输入芯片id-"/>&nbsp;
						<button class="search_button" type="button">搜索</button>
					</form>
				
			</div>
			<div id="searchResult" class="searchResult">
			
				<table id="resultTable" cellpadding="0px" border="2px" cellspacing="0px" style="color:#fff;
				">
					<tr><th>id</th><th>芯片id</th><th>所属区域编号</th><th>地址</th><th>节点类型</th><th>状态</th><th>修改服务器</th></tr>
				</table>
			</div>
		</div>
		<div class="foot">
	        <p align="center">Copyright © 1996 - 2016 w &amp; c. All Rights Reserved.</p>
	        <p align="center">Powered By:lauwen &amp; cc.</p>
	    </div>
	</div>
</body>
<script type="text/javascript">
	$(".search_button").click(function() {
		console.log("enterClick");
		var regionNum = $("#regionNum").val();
		var deviceType = $("#deviceType").val();
		var chipId = $("#chipId").val();

		console.log("enterAjaxPrev"+"regionnum"+regionNum+"devicetype"+deviceType);
		$.ajax({
			url: "<?php echo U('Index/classifySearch');?>",
			type: 'post',
			dataType: 'json',
			data: {regionNum: regionNum,deviceType:deviceType,chipId:chipId},
			success:function(data){

				console.log("ajaxSuccess");
				var da = eval("("+data+")");
				console.log("aaa"+da.length);

				$("td").parent().remove();
				$("#searchResult").addClass('searchResultBlock');
				if(chipId !== ""){
					console.log("000");
					alert("000");
					var htmlContent = "<tr><td>"+da['id']+"</td><td>"+da['chipid']+"</td><td>"+da['regionnum']+"</td><td>"+da['deviceadd']+"</td><td>"+da['devicetype']+"</td><td>"+da['devicestate']+"</td></tr>";
					$("#resultTable").append(htmlContent);
				}else{
					console.log("101");
					if(!regionNum && !deviceType){
						console.log("all");
						$.each(da,function(index,item){
							// console.log(item['regionNum']);
							var devideContent = "<tr><td colspan='6' align='center'>"+item['regionNum']+"</td></tr>";
							$("#resultTable").append(devideContent);
							$.each(item['val'],function(index,element){
								console.log(element['regionnum']);
								var htmlContent = "<tr><td>"+element['id']+"</td><td>"+element['chipid']+"</td><td>"+element['regionnum']+"</td><td>"+element['deviceadd']+"</td><td>"+element['devicetype']+"</td><td>"+element['devicestate']+"</td></tr>";
								$("#resultTable").append(htmlContent);
							});
						});
					}else{
					console.log("222");
					// alert("222");
						$.each(da,function(index,item){
							var htmlContent = "<tr><td>"+da[index]['id']+"</td><td>"+da[index]['chipid']+"</td><td>"+da[index]['regionnum']+"</td><td>"+da[index]['deviceadd']+"</td><td>"+da[index]['devicetype']+"</td><td>"+da[index]['devicestate']+"</td></tr>";
							$("#resultTable").append(htmlContent);
							// <td><a href='"+<?php echo U('');?>+"'></td>
						});

					}
					
				}
			}
		});
	});
	
	
	
</script>
</html>